#include <stdio.h>
#include <unistd.h>

static char *strpy(char c, int n)
{ 
    static char buf[128] = {0};
    for (int i = 0; i < n; i++)
        buf[i] = c;
    buf[n] = 0;
    return buf;
}

/*
 * p: 0 ~ 1.0, percent
 * w: width
 * */
static void progress_bar(float p, int w)
{
    int n = (int)(p * w);

    printf("\r");
    printf("%s", strpy('#', n));
    printf("%s", strpy('.', w - n));
    fflush(stdout);

    if ((int)p >= 1) {
        printf("\n");
    }
}

int main()
{
    for (int i = 0; i < 101; i++) {
        progress_bar(i/100.0, 50);
        usleep(1000 * 5);
    }
}
